// var path = require("path");
var webpack = require("webpack");
module.exports = {
  css: {
    loaderOptions: {
      less: {
        javascriptEnabled: true,
        // 在ant design的官网中有定制主题的章节，其原理就是改变less的内置变量
        modifyVars: {
          "primary-color": "#1DA57A"
        }
      }
    }
  },
  configureWebpack: {
    plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)],
    resolve: {
      alias: {
        // 图标的优化，需要在icons.js里加载每一个使用到的图标，很繁琐
        // "@ant-design/icons/lib/dist$": path.resolve(__dirname, "./src/icons.js")
      }
    }
  },
  // 通过`vue inspect`查看内置的loader
  chainWebpack: config => {
    const svgRule = config.module.rule("svg");
    svgRule.uses.clear();
    svgRule.use("vue-svg-loader").loader("vue-svg-loader");
  },
  devServer: {
    proxy: {
      mock: {
        target: "http://localhost:8080",
        bypass: function(req, res) {
          if (req.headers.accept.indexOf("html") !== -1) {
            return "/index.html";
          } else if (process.env.MOCK !== "none") {
            // if (req.path.indexOf(`.json`)) {
            //   return;
            // }
            const name = req.path
              .split("/api/")[1]
              .split("/")
              .join("_");
            const mock = require(`./src/mock/${name}`);
            const result = mock(req.method);
            delete require.cache[require.resolve(`./src/mock/${name}`)];
            return res.send(result);
          }
        }
      }
    }
  }
};
